package com.softer.wxzj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.common.enums.MessageEnum;
import com.softer.wxzj.common.enums.NumStrEnum;
import com.softer.wxzj.common.enums.ShiroResultEnum;
import com.softer.wxzj.common.error.CourseException;
import com.softer.wxzj.common.util.StringUtils;
import com.softer.wxzj.entity.*;
import com.softer.wxzj.mapper.*;
import com.softer.wxzj.service.BaseModifyDetailService;
import com.softer.wxzj.service.ZoneCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = {RuntimeException.class, Exception.class})
public class BaseModifyDetailServiceImpl implements BaseModifyDetailService {
    @Autowired
    BaseModifyDetailMapper baseModifyDetailMapper;
    @Autowired
    BaseRegionInfoMapper baseRegionInfoMapper;
    @Autowired
    ZoneCodeMapper zoneCodeMapper;
    @Autowired
    private BaseModifyDetailMapper modifyDetailMapper;
    @Autowired
    private BaseModifyReqMapper baseModifyReqMapper;
    @Autowired
    private BaseHouseInfoMapper baseHouseInfoMapper;
    @Autowired
    private DicContentMapper dicContentMapper;
    @Autowired
    private BaseBuildInfoMapper baseBuildInfoMapper;
    @Autowired
    private BaseSubRegionInfoMapper baseSubRegionInfoMapper;
    @Autowired
    private BaseCellInfoMapper baseCellInfoMapper;
    @Autowired
    private DepModeInfoMapper depModeInfoMapper;
    @Autowired
    private ZoneCodeService zoneCodeService;
    @Autowired
    private DepModeInfoServiceImpl depModeInfoService;

    @Override
    public CommonResult insert(BaseModifyDetail baseModifyDetail) {

        return null;
    }

    @Override
    public CommonResult update(BaseModifyDetail baseModifyDetail) {
        return null;
    }

    @Override
    public CommonResult delete(String id) {
        return null;
    }

    @Override
    public PageInfo<BaseModifyDetail> getList(Page page, BaseModifyDetail baseModifyDetail) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<BaseModifyDetail> list = baseModifyDetailMapper.getList(baseModifyDetail);
        for (BaseModifyDetail baseModifyDetail1 : list) {

            switch (baseModifyDetail1.getColumnName()) {
                case "regionNo":
                    String newValue = "";
                    String oldValue = "";
                    if (StringUtils.isNotBlank(baseModifyDetail1.getNewValue())) {
                        List<String> regs = baseRegionInfoMapper.getRegionNameByIdList(baseModifyDetail1.getNewValue());
                        if (regs.size() > 0) {
                            for (String reg : regs) {
                                baseModifyDetail1.setNewValue(newValue + reg);
                            }
                        }
                    }
                    if (StringUtils.isNotBlank(baseModifyDetail1.getOldValue())) {
                        List<String> regs = baseRegionInfoMapper.getRegionNameByIdList(baseModifyDetail1.getOldValue());
                        if (regs.size() > 0) {
                            for (String reg : regs) {
                                baseModifyDetail1.setOldValue(oldValue + reg);
                            }
                        }
                    }
                    break;
                case "regionCode":
                    String newName = "";
                    String oldName = "";
                    String newRegionCode = baseModifyDetail1.getNewValue();
                    String oldRegionCode = baseModifyDetail1.getOldValue();
                    ZoneCode newZoneCode = zoneCodeMapper.getInfoByZoneCode(newRegionCode);
                    ZoneCode oldZoneCode = zoneCodeMapper.getInfoByZoneCode(oldRegionCode);
                    newName = zoneCodeService.zoneName(newZoneCode);
                    oldName = zoneCodeService.zoneName(oldZoneCode);
                    baseModifyDetail1.setNewValue(newName);
                    baseModifyDetail1.setOldValue(oldName);
                    break;
            }

        }
        PageInfo<BaseModifyDetail> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public BaseModifyDetail getInfo(String id) {
        return baseModifyDetailMapper.getInfo(id);
    }

    /**
     * 新增房屋
     *
     * @param reqNo
     * @return
     */
    @Override
    public List<BaseHouseInfo> selectAllList(String reqNo) {
        //获取房屋的列名称
        List<String> list = modifyDetailMapper.getColumnListByHouse(reqNo);
        Map<String, Object> map = new HashMap<>(8);
        //所有新增单元id
        List<BaseCellInfo> base = new ArrayList<>();
        List<String> cellId = new ArrayList<>();
        map.put("list", list);
        map.put("reqNo", reqNo);
        List<BaseHouseInfo> lis = baseModifyDetailMapper.selectAllList(map);
        BaseBuildInfo baseBuildInfo = baseBuildInfoMapper.getInfo(lis.get(0).getBuildNo());
        BaseRegionInfo baseRegionInfo = baseRegionInfoMapper.getInfo(baseBuildInfo.getRegionNo());
        String zone = zoneCodeMapper.selectZoneCode(baseRegionInfo.getZoneCode()).getZoneName();
        String sub = "";
        if (StringUtils.isNotBlank(baseBuildInfo.getSubRegionNo())) {
            sub = baseSubRegionInfoMapper.getInfo(baseBuildInfo.getSubRegionNo()).getSubRegionName();
        }

        for (BaseHouseInfo b : lis) {
            String name = "";
            //查看单元名称是否变更若变更则地址是新的
            name = baseModifyDetailMapper.selectCountChangeCellByName(reqNo, b.getCellNo());
            if (StringUtils.isBlank(name)) {
                name = baseCellInfoMapper.getInfo(b.getCellNo()).getCellName();
            }
            BaseCellInfo cellInfo = new BaseCellInfo();
            if (base.isEmpty()) {
                cellInfo = baseCellInfoMapper.getInfo(b.getCellNo());
                //如果没有则是单元新增的去变更表查询
                if (null == cellInfo) {
                    cellInfo = new BaseCellInfo();
                    cellInfo.setId(b.getCellNo());
                }
                cellInfo.setCellName(name);
                base.add(cellInfo);
            } else {
                if (!cellId.contains(b.getCellNo())) {
                    cellInfo = baseCellInfoMapper.getInfo(b.getCellNo());
                    if (null == cellInfo) {
                        cellInfo = new BaseCellInfo();
                        cellInfo.setCellName(name);
                        cellInfo.setId(b.getCellNo());
                    }
                    base.add(cellInfo);
                }
            }
            cellId.add(b.getCellNo());
            DepModeInfo depModeInfo = new DepModeInfo();
            depModeInfo.setHouseId(b.getId());
            depModeInfo.setHouseType(b.getHouseAttr());
            List<DepModeInfo> depModeInfos = depModeInfoService.selectByAllChange(depModeInfo);
            b.setDepModeInfos(depModeInfos);

            String useNsme = dicContentMapper.selectName(b.getHouseUse());
            b.setHouseUseName(useNsme);
            b.setBuildName(baseBuildInfo.getBuildName());
            b.setCellName(name);
            b.setZoneName(zone);
            b.setRegionName(baseRegionInfo.getRegionName());
            b.setSubRegionName(sub);
        }
        lis.get(0).setBaseCellInfos(base);
        return lis;
    }

    /**
     * 添加房屋信息
     *
     * @param baseHouseInfo
     * @return
     */
    @Override
    @Transactional
    public CommonResult addHouse(List<BaseHouseInfo> baseHouseInfo) {
        int no = 1;
        String reqNo = baseHouseInfo.get(0).getReqNo();
        if (null == baseHouseInfo) {
            throw new CourseException(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
        }
        for (BaseHouseInfo b : baseHouseInfo) {
            no = baseModifyDetailMapper.addHouse(b.getId(), "houseAttr", b.getHouseAttr(), reqNo);
            if (no == 0) {
                throw new CourseException(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
            }
            if (null == b.getStruArea()) {
                b.setStruArea(BigDecimal.ZERO);
            }
            no = baseModifyDetailMapper.addHouse(b.getId(), "struArea", b.getStruArea().toString(), reqNo);
            if (no == 0) {
                throw new CourseException(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
            }
            no = baseModifyDetailMapper.addHouse(b.getId(), "firstMode", b.getFirstMode(), reqNo);
            if (no == 0) {
                throw new CourseException(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
            }
            no = baseModifyDetailMapper.addHouse(b.getId(), "roomName", b.getRoomName(), reqNo);
            if (no == 0) {
                throw new CourseException(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
            }
            no = baseModifyDetailMapper.addHouse(b.getId(), "houseSite", b.getHouseSite(), reqNo);
            if (no == 0) {
                throw new CourseException(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
            }
        }
//        no = baseModifyReqMapper.updateMsg(baseHouseInfo.get(0).getReqNo(), baseHouseInfo.get(0).getMsg());
//        if (StringUtils.isNotBlank(baseHouseInfo.get(0).getMsg())) {
//            if (no == 0) {
//                throw new CourseException(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
//            }
//        }
        return CommonResult.ResponseResult(no);
    }

    @Override
    public CommonResult delHouse(String id, String reqNo) {
        int no = baseModifyDetailMapper.delHouse(id, reqNo);
        return CommonResult.ResponseResult(no);
    }

    /**
     * 查看结构变更房屋是否要跳页
     *
     * @param reqNo
     * @return
     */
    @Override
    public int changePage(String reqNo) {
        return baseModifyDetailMapper.changePage(reqNo);
    }

    @Override
    public PageInfo<BaseModifyDetail> getListByCell(Page page, String id) {
        List<BaseModifyDetail> b = new ArrayList<>();
        //单元添加
        List<String> cellIdAdds = baseModifyDetailMapper.selectByReqNoTypeCell(id, NumStrEnum.ZERO.getNum());
        Map map = new HashMap();
        List<String> cellName = baseModifyDetailMapper.getColumnListAndCell(id);
        map.put("list", cellName);
        map.put("reqNo", id);
        for (String cellId : cellIdAdds) {
            map.put("id", cellId);
            BaseCellInfo baseCellInfo = baseModifyDetailMapper.selectAddCell(map);
            String elevator = "";
            if (baseCellInfo.getElevator().equals(NumStrEnum.ZERO.getNum())) {
                elevator = "否";
            } else {
                elevator = "是";
            }
            BaseModifyDetail baseModifyDetail = new BaseModifyDetail();
            baseModifyDetail.setName("单元添加");
            baseModifyDetail.setOldValue("----------");
            baseModifyDetail.setNewValue(baseCellInfo.getCellName() + "--" + baseCellInfo.getStartFloor() + "--" + baseCellInfo.getEndFloor() + "--" + baseCellInfo.getHouseNum() + elevator);
            b.add(baseModifyDetail);
        }
        //单元删除
        List<String> cellIddels = baseModifyDetailMapper.deleCellId(id);
        for (String cellId : cellIddels) {
            map.put("id", cellId);
            map.put("reqNo",id);
            BaseCellInfo baseCellInfo = baseModifyDetailMapper.selectOldCell(map);
            String elevator = "";
            if (StringUtils.isNotBlank(baseCellInfo.getElevator())) {
                if (baseCellInfo.getElevator().equals(NumStrEnum.ZERO.getNum())) {
                    elevator = "否";
                } else {
                    elevator = "是";
                }
            }
            BaseModifyDetail baseModifyDetail = new BaseModifyDetail();
            baseModifyDetail.setName("单元删除");
            baseModifyDetail.setNewValue("----------");
            baseModifyDetail.setOldValue(baseCellInfo.getCellName() + "--" + baseCellInfo.getStartFloor() + "--" + baseCellInfo.getEndFloor() + "--" + baseCellInfo.getHouseNum()+ "--" +elevator);
            b.add(baseModifyDetail);
        }
        //单元修改
        List<String> listChangeId = baseModifyDetailMapper.selectChangeCell(id);
        for (String changeId : listChangeId) {
            map.put("id", changeId);
            BaseCellInfo baseCellInfo = baseModifyDetailMapper.selectAddCell(map);
            BaseCellInfo baseCellInfoOld = baseModifyDetailMapper.selectOldCell(map);
            BaseCellInfo baseChange = baseCellInfoMapper.getInfo(changeId);
            if (null == baseCellInfoOld.getCellName()) {
                if (null != baseChange) {
                    baseCellInfo.setCellName(baseChange.getCellName());
                    baseCellInfoOld.setCellName(baseChange.getCellName());
                } else {
                    baseCellInfo.setCellName("该单元已删除");
                    baseCellInfoOld.setCellName("该单元已删除");
                }
            }
            if (null == baseCellInfoOld.getStartFloor()) {
                if (null != baseChange) {
                    baseCellInfo.setStartFloor(baseChange.getStartFloor());
                    baseCellInfoOld.setStartFloor(baseChange.getStartFloor());
                } else {
                    baseCellInfo.setCellName("");
                    baseCellInfoOld.setCellName("");
                }
            }
            if (null == baseCellInfoOld.getEndFloor()) {
                if (null != baseChange) {
                    baseCellInfo.setEndFloor(baseChange.getEndFloor());
                    baseCellInfoOld.setEndFloor(baseChange.getEndFloor());
                } else {
                    baseCellInfo.setEndFloor("");
                    baseCellInfoOld.setEndFloor("");
                }
            }
            if (null == baseCellInfoOld.getHouseNum()) {
                if (null != baseChange) {
                    baseCellInfo.setHouseNum(baseChange.getHouseNum());
                    baseCellInfoOld.setHouseNum(baseChange.getHouseNum());
                } else {
                    baseCellInfo.setHouseNum("");
                    baseCellInfoOld.setHouseNum("");
                }
            }
            if (null == baseCellInfoOld.getElevator()) {
                if (null != baseChange) {
                    if ((NumStrEnum.ZERO.getNum()).equals(baseChange.getElevator())) {
                        baseCellInfo.setElevator("否");
                        baseCellInfoOld.setElevator("否");
                    } else {
                        baseCellInfo.setElevator("是");
                        baseCellInfoOld.setElevator("是");
                    }
                } else {
                    baseCellInfo.setElevator("");
                    baseCellInfoOld.setElevator("");
                }
            } else {
                if ((NumStrEnum.ZERO.getNum()).equals(baseCellInfoOld.getElevator())) {
                    baseCellInfoOld.setElevator("否");
                } else {
                    baseCellInfoOld.setElevator("是");
                }
                if ((NumStrEnum.ZERO.getNum()).equals(baseCellInfo.getElevator())) {
                    baseCellInfo.setElevator("否");
                } else {
                    baseCellInfo.setElevator("是");
                }
            }
            BaseModifyDetail baseModifyDetail = new BaseModifyDetail();
            baseModifyDetail.setName("单元修改");
            baseModifyDetail.setOldValue(baseCellInfoOld.getCellName() + "--" + baseCellInfoOld.getStartFloor() + "--" + baseCellInfoOld.getEndFloor() + "--" + baseCellInfoOld.getHouseNum() + "--" + baseCellInfoOld.getElevator());
            baseModifyDetail.setNewValue(baseCellInfo.getCellName() + "--" + baseCellInfo.getStartFloor() + "--" + baseCellInfo.getEndFloor() + "--" + baseCellInfo.getHouseNum() + "--" + baseCellInfo.getElevator());
            b.add(baseModifyDetail);
        }
        //todo
        List<String> ids = baseModifyDetailMapper.getModifyDetailHouseId(id);
        for (int i = 0; i < ids.size(); i++) {
            BaseModifyDetail baseList = new BaseModifyDetail();
            List<BaseModifyDetail> baseModifyDetail = baseModifyDetailMapper.getModifyDetailHouseIdList(ids.get(i), id);
            String roomName = "";
            String houseSite = "";
            String houseUse = "";
            String houseAttr = "";
            String struArea = "";
            String firstDue = "";
            for (BaseModifyDetail base : baseModifyDetail) {
                switch (base.getColumnName()) {
                    case "roomName":
                        roomName = base.getNewValue();
                        break;
                    case "houseSite":
                        houseSite = base.getNewValue();
                        break;
                    case "houseUse":
                        if (StringUtils.isNotBlank(base.getNewValue())) {
                            houseUse = dicContentMapper.selectName(base.getNewValue());
                        }
                        break;
                    case "houseAttr":
                        if (StringUtils.isNotBlank(base.getNewValue())) {
                            houseAttr = dicContentMapper.selectName(base.getNewValue());
                        }
                        break;
                    case "struArea":
                        if (StringUtils.isNotBlank(base.getNewValue())) {
                            struArea = base.getNewValue();
                        }
                        break;
                    case "firstMode":
                        if (StringUtils.isNotBlank(base.getNewValue())) {
                            firstDue = depModeInfoMapper.getInfo(base.getNewValue()).getName();
                        }
                        break;
                }
                if (("id").equals(base.getColumnName())) {
                    if (StringUtils.isBlank(base.getNewValue())) {
                        baseList.setName("删除房屋");
                    } else {
                        baseList.setName("新增房屋");
                    }
                }
            }
            if (("删除房屋").equals(baseList.getName())) {
                List<String> list = modifyDetailMapper.getColumnListByHouse(id);
                Map<String, Object> maps = new HashMap<>(8);
                maps.put("list", list);
                maps.put("reqNo", id);
                maps.put("id", ids.get(i));
                BaseHouseInfo base = baseModifyDetailMapper.selectHouseAllListOld(maps);
                String accr = "";
                String use = "";
                if (StringUtils.isNotBlank(base.getHouseAttr())) {
                    accr = dicContentMapper.selectName(base.getHouseAttr());
                }

                if (StringUtils.isNotBlank(base.getHouseUse())) {
                    use = dicContentMapper.selectName(base.getHouseUse());
                }
                String mode = "";
                if (StringUtils.isNotBlank(base.getFirstMode())) {
                    mode = depModeInfoMapper.getInfo(base.getFirstMode()).getName();

                }
                baseList.setNewValue("----------");
                baseList.setOldValue(base.getRoomName() + "--" + base.getHouseSite() + "--" + accr + "--" + use + "--" + mode + "--" + base.getStruArea());
            } else {
                baseList.setOldValue("----------");
                baseList.setNewValue(roomName + "--" + houseSite + "--" + houseAttr + "--" + houseUse + "--" + firstDue + "--" + struArea);
            }
            b.add(baseList);
        }
        PageInfo<BaseModifyDetail> pageInfo = new PageInfo<>();
        if (null != b && b.size() > 0) {
            pageInfo = new PageInfo<>(pageAll(page, b));
            pageInfo.setTotal(b.size());
        }
        return pageInfo;
    }

    /**
     * 变更审核查询详情列表
     *
     * @param page
     * @param id
     * @return
     */
    @Override
    public PageInfo<BaseModifyDetail> getListByHouse(Page page, String id) {
        List<BaseModifyDetail> baseList = new ArrayList<>();
        //查询删除房屋id
        String delId = baseModifyDetailMapper.selectDelHouse(id, null);
        if (StringUtils.isNotBlank(delId)) {
            String[] idList = delId.split(",");
            for (String del : idList) {
                List<String> list = modifyDetailMapper.getColumnListByHouse(id);
                Map<String, Object> map = new HashMap<>(8);
                map.put("list", list);
                map.put("reqNo", id);
                map.put("id", del);
                BaseHouseInfo baseHouseInfo = baseModifyDetailMapper.selectHouseAllListOld(map);
                BaseModifyDetail baseModifyDetail = new BaseModifyDetail();
                baseModifyDetail.setName("删除房屋");
                baseModifyDetail.setNewValue("--" + "--" + " " + "--" + " " + "--" + " " + "--" + " " + "--");
                String accr = dicContentMapper.selectName(baseHouseInfo.getHouseAttr());
                if (null == accr) {
                    accr = "";
                }
                String use = dicContentMapper.selectName(baseHouseInfo.getHouseUse());
                String mode = "";
                if (null != baseHouseInfo.getFirstMode()) {
                    depModeInfoMapper.getInfo(baseHouseInfo.getFirstMode()).getName();
                }
                baseModifyDetail.setOldValue(baseHouseInfo.getRoomName() + "--" + baseHouseInfo.getHouseSite() + "--" + accr + "--" + use + "--" + mode + "--" + baseHouseInfo.getStruArea());
                baseList.add(baseModifyDetail);
            }
        }//查询新增房屋
        List<String> ids = baseModifyDetailMapper.selectAddHouse(id, NumStrEnum.ONE.getNum());
        for (String idAdd : ids) {
            List<String> list = modifyDetailMapper.getColumnListByHouse(id);
            Map<String, Object> map = new HashMap<>(8);
            map.put("list", list);
            map.put("reqNo", id);
            map.put("id", idAdd);
            BaseHouseInfo baseHouseInfo = baseModifyDetailMapper.selectHouseAllList(map);
            BaseModifyDetail baseModifyDetail = new BaseModifyDetail();
            baseModifyDetail.setName("新增房屋");
            String accr = dicContentMapper.selectName(baseHouseInfo.getHouseAttr());
            if (null == accr) {
                accr = "";
            }
            String use = dicContentMapper.selectName(baseHouseInfo.getHouseUse());
            String mode = "";
            if (null != baseHouseInfo.getFirstMode()) {
                mode = depModeInfoMapper.getInfo(baseHouseInfo.getFirstMode()).getName();
            }
            baseModifyDetail.setOldValue("--" + "--" + " " + "--" + " " + "--" + " " + "--" + " " + "--");
            baseModifyDetail.setNewValue(baseHouseInfo.getRoomName() + "--" + baseHouseInfo.getHouseSite() + "--" + accr + "--" + use + "--" + mode + "--" + baseHouseInfo.getStruArea());
            baseList.add(baseModifyDetail);
        }

        List<String> change = baseModifyDetailMapper.selectBusinessNextByReqNoId(id);
        List<String> changeHouseInfo = modifyDetailMapper.reqNoChangeHouse(id);
        for (String chang : changeHouseInfo) {
            change.add(chang);
        }

        for (String changeId : change) {
            int changeHouse = baseModifyDetailMapper.selectChangeHouseById(id, changeId);
            if (changeHouse == 0) {
                List<String> list = modifyDetailMapper.getColumnListByHouse(id);
                Map<String, Object> map = new HashMap<>(8);
                map.put("list", list);
                map.put("reqNo", id);
                map.put("id", changeId);
                BaseHouseInfo baseHouseInfo = baseModifyDetailMapper.selectHouseAllList(map);
                BaseHouseInfo b = baseModifyDetailMapper.selectHouseAllListOld(map);
                BaseHouseInfo base = baseHouseInfoMapper.getInfo(changeId);
                if (StringUtils.isBlank(baseHouseInfo.getRoomName())) {
                    baseHouseInfo.setRoomName(base.getRoomName());
                    b.setRoomName(base.getRoomName());

                }
                if (StringUtils.isBlank(baseHouseInfo.getHouseSite())) {
                    baseHouseInfo.setHouseSite(base.getHouseSite());
                    b.setHouseSite(base.getHouseSite());
                }
                if (StringUtils.isBlank(baseHouseInfo.getHouseUse())) {
                    baseHouseInfo.setHouseUse(base.getHouseUse());
                    b.setHouseUse(base.getHouseUse());
                }
                if (StringUtils.isBlank(baseHouseInfo.getFirstMode())) {
                    baseHouseInfo.setFirstMode(base.getFirstMode());
                    b.setFirstMode(base.getFirstMode());
                }
                BaseModifyDetail baseModifyDetail = new BaseModifyDetail();
                baseModifyDetail.setName("修改房屋");
                String accr = "";
                String newAccr = "";
                String use = "";
                String newUse = "";
                if (StringUtils.isNotBlank(b.getHouseAttr())) {
                    accr = dicContentMapper.selectName(b.getHouseAttr());
                } else {
                    accr = dicContentMapper.selectName(base.getHouseAttr());
                }
                if (StringUtils.isNotBlank(baseHouseInfo.getHouseAttr())) {
                    newAccr = dicContentMapper.selectName(baseHouseInfo.getHouseAttr());
                } else {
                    newAccr = dicContentMapper.selectName(base.getHouseAttr());

                }
                if (StringUtils.isNotBlank(b.getHouseUse())) {
                    use = dicContentMapper.selectName(b.getHouseUse());
                } else {
                    use = dicContentMapper.selectName(base.getHouseUse());
                }
                if (StringUtils.isNotBlank(baseHouseInfo.getHouseUse())) {
                    newUse = dicContentMapper.selectName(baseHouseInfo.getHouseUse());
                } else {
                    newUse = dicContentMapper.selectName(base.getHouseUse());

                }
                String mode = "";
                if (StringUtils.isNotBlank(b.getFirstMode())) {
                    mode = depModeInfoMapper.getInfo(b.getFirstMode()).getName();

                }
                String newMode = depModeInfoMapper.getInfo(baseHouseInfo.getFirstMode()).getName();
                String roomName = "";
                String houseSite = "";
                if (StringUtils.isNotBlank(b.getRoomName())) {
                    roomName = b.getRoomName();
                }
                if (StringUtils.isNotBlank(b.getHouseSite())) {
                    houseSite = b.getHouseSite();
                }
                baseModifyDetail.setOldValue(roomName + "--" + houseSite + "--" + accr + "--" + use + "--" + mode);
                if (b.getStruArea() == null || b.getStruArea().compareTo(BigDecimal.ZERO) == 0) {
                    baseModifyDetail.setOldValue(baseModifyDetail.getOldValue() + "--" + 0);
                } else {
                    baseModifyDetail.setOldValue(baseModifyDetail.getOldValue() + "--" + b.getStruArea());
                }
                baseModifyDetail.setNewValue(baseHouseInfo.getRoomName() + "--" + baseHouseInfo.getHouseSite() + "--" + newAccr + "--" + newUse + "--" + newMode);
                if (baseHouseInfo.getStruArea() == null || baseHouseInfo.getStruArea().compareTo(BigDecimal.ZERO) == 0) {
                    baseModifyDetail.setNewValue(baseModifyDetail.getNewValue() + "--" + 0);
                } else {
                    baseModifyDetail.setNewValue(baseModifyDetail.getNewValue() + "--" + baseHouseInfo.getStruArea());
                }
                baseList.add(baseModifyDetail);
            }
        }
        PageInfo<BaseModifyDetail> pageInfo = new PageInfo<>();
        if (baseList != null && baseList.size() > 0) {
            pageInfo = new PageInfo<>(pageAll(page, baseList));
            pageInfo.setTotal(baseList.size());
        }

        return pageInfo;
    }

    public List pageAll(Page page, List baseModifyDetail) {
        int total = baseModifyDetail.size();
        int fromIndex = 0; // 从哪里开始截取
        int toIndex = 0; // 截取几个
        List<BaseModifyDetail> detailPojos = new ArrayList<>();
        if (baseModifyDetail != null && baseModifyDetail.size() > 0) {
            // 当前页小于或等于总页数时执行
            if (page.getPageNum() <= total && page.getPageNum() != 0) {
                fromIndex = (page.getPageNum() - 1) * page.getPageSize();
                if (Integer.valueOf(page.getPageNum()) == total) {
                    toIndex = baseModifyDetail.size();
                } else {
                    toIndex = page.getPageNum() * page.getPageSize();
                }
            }
            if (baseModifyDetail.size() <= toIndex) {
                if (fromIndex == 0) {
                    detailPojos = baseModifyDetail.subList(fromIndex, baseModifyDetail.size());
                } else {
                    try {
                        detailPojos = baseModifyDetail.subList(fromIndex, baseModifyDetail.size());
                    } catch (Exception e) {
                        detailPojos = new ArrayList<>();
                    }
                }
            } else {
                detailPojos = baseModifyDetail.subList(fromIndex, toIndex);
            }

        }
        return detailPojos;
    }
}

